<!-- 检查详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 32rpx;" slot="content">检查详情</block>
		</cu-custom>
		<view class="content" style="background: none;flex: 1;">
			<ul style="background: #fff;">
				<li>
					<text class="list-info">任务名称：</text>
					<text class="list-title">{{ inspectData.title || "暂无" }}</text>
				</li>
				<li>
					<text class="list-info">检查人员：</text>
					<text class="list-title">{{ inspectData.inspectPersonName || "暂无" }}</text>
				</li>
				<li>
					<text class="list-info">被检单位：</text>
					<text class="list-title">{{ inspectData.inspectEnterpriseName || "暂无" }}</text>
				</li>
				<li>
					<text class="list-info">检查时间：</text>
					<text class="list-title">{{ (inspectData.inspectTime | dateFormat ) || "暂无"}}</text>
				</li>
				<li>
					<text class="list-info">任务状态：</text>
					<text class="list-title">{{ inspectFormat(inspectData.status) }}</text>
				</li>
			</ul>
			<view class="detail" @click="closeDetail">
				<view class="detail-title">
					检查设备信息
					</view>
					<uni-icons class="close" :type="picon" size="16"></uni-icons>
				</view>
			<view v-if="show && inspectData.ininspectItemModelList.length" class="detail-box">
				<view class="zj " v-for="(value, key) in inspectData.ininspectItemModelList" :key="key">
					<view style="white-space: nowrap;">{{ value.type }}：已完成 <text class="title_big state-green">{{ value.ywcsl }}</text> 个 / 需要完成 <text
							class="title_big">{{ value.xywcsl }}</text> 个
					</view>
					<!-- v-if="!!value.ywcsl" -->
						<button  class="my-btn cu-btn bg-system-orange shadow btn-small" @click="viewDetail(value)">详情</button>
				</view>
			</view>
		</view>
			<view class="flex btns-group">
			<button class="my-btn-grpup" v-if="inspectData.status == '01'" @tap="startTask(ucId)">确认任务</button>
			<button class="my-btn-grpup" v-if="inspectData.status == '10'" @tap="startExecute(ucId)">开始执行</button>
			<button class="my-btn-grpup" v-if="inspectData.status == '20'" @tap="stopTask(ucId)">暂停任务</button>
			<button class="my-btn-grpup" v-if="inspectData.zs == inspectData.zwcs && this.inspectData.status == '20'"
				@tap="endTask(ucId)">结束本次检测任务/结束检测任务</button>
		</view>

		<view>
			<u-toast ref="uToast" />
		</view>
		<message />
	</view>
</template>

<script>
export default {
	data() {
		return {
			inspectData: {},
			inspectTpe: '未进行', //未进行 进行中 已完成
			dlist: [],
			tipMessage: '',
			ucId: '',
			xwc: 0,
			ywc: 0,
			picon: 'top',
			show: false,
			inspectOptions: [],
			statusOptions: []
		}
	},
	onLoad(option) {
		// 封装参数
		this.ucId = option.ucId
		
	},
	onShow() {
		let that = this
		this.getDicts("inspect_status", that).then(response => {
			that.inspectOptions = response.data.data;
		});
		this.xq()
	},
	methods: {
		viewDetail(val) {
			uni.navigateTo({
				url: './jcxqdetail?maintenanceId='+ val.maintenanceId + '&typeCode=' + val.typeCode + '&typeId=' + val.typeId
			})
		},
		closeDetail() {
			this.show = !this.show
			this.picon = this.show ? 'bottom' : 'top'
		},
		stopTask(val) {
			let that = this
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/inspect/stopTask',
				data: { ucId: val }
			}).then(function (res) {
				that.xq()
			}).catch(function (e) {
				console.error(e)
			})
		},
		statusFormat(data) {
			return this.selectDictLabel(this.statusOptions, data);
		},
		inspectFormat(data) {
			return this.selectDictLabel(this.inspectOptions, data);
		},
		collapseChange(item, index) {
			setTimeout(() => {
				this.$refs.collapseMain.resize()
			}, 50)
		},
		//开始任务
		startTask(val) {
			let that = this
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/inspect/startTask',
				data: { ucId: val }
			}).then(function (res) {
				that.xq(that.ucId)
			}).catch(function (e) {
				console.error(e)
			})
		},
		startExecute(val) {
			let that = this
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/inspect/startExecute',
				data: { ucId: val }
			}).then(function (res) {
				console.info(res.data.data)
				if (res.data.data.code == 200) {
					that.xq()
				} else {
					that.$refs.uToast.show({
						message: res.data.data.msg,
						type: 'error',
						complete() {
							that.refresh()
						}
					})
				}
			}).catch(function (e) {
				console.error(e)
			})
		},
		open() {
			this.$refs.popup.open('center')
		},
		jc(id) {
			uni.navigateTo({
				url: '/jcqy/jcxm/jcxm?ucId=' + id
			})
		},
		see_detail(index) {
			console.info("index:" + index)
		},
		close() {
			this.pShow = !this.pShow;
			this.iconStyle = !!this.pShow ? 'bottom' : 'top'
		},
		xq() {
			let that = this
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/inspect/' + that.ucId,
				method: "GET"
			}).then(function (res) {
				that.inspectData = res.data.data.data
			}).catch(function (e) {
				console.error(e)
			})
		},
		reportHiddenDanger(mainDataId, equipmentId) {
			uni.navigateTo({
				url: '/wb/yhsb/yhsbym?ucId=' + this.ucId + '&equipmentId=' + equipmentId + '&mainDataId=' + mainDataId
			});
		},
		sbFire(item) {
			let that = this
			// 封装参数
			let params = {
				"ucId": item.equipmentId
			}
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/maintenance/wbFire',
				data: params
			}).then(function (res) {
				that.xq()
			}).catch(function (e) {

			})
		},
		wbCheck(item) {
			let that = this
			// 封装参数
			let params = {
				"ucId": item.equipmentId,
				"modelId": item.ucId
			}
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/maintenance/wbCheck',
				data: params
			}).then(function (res) {
				that.xq()
			}).catch(function (e) {

			})
		},
	}
}
</script>

<style lang="scss" scoped>
.list-item {
	padding: 20rpx 40rpx;
	background-color: #fff;
	border-bottom: #999999 1px dashed;

	.list-bottom {
		margin-top: 55rpx;
	}

	.list-center {
		margin-top: 20rpx;
		font-size: 28rpx;
		color: #999999;
	}
}

.collapse-title {
	padding: 0px 9px;
}

.uni-collapse-cell--open {
	background-color: #FFFFFF !important;
}

.page {
	width: 100vw;
	min-height: 100vh;
	position: absolute;
	display: flex;
	flex-direction: column;
}

.content {
	margin-top: 24rpx;
	background-color: #FFFFFF;
}

ul li {
	list-style: none;
	margin: 0;
	padding: 0;
	margin-left: 24rpx;
	position: relative;
}

li text {
	font-size: 24rpx;
	line-height: 94rpx;
}

li::after {
	content: '';
	position: absolute;
	left: 2rpx;
	bottom: 0;
	right: 2rpx;
	height: 1px;
	background-color: #dcdcdc;
}


.detail {
	width: 100%;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	padding: 10px;
	box-sizing: border-box;
	background: #fff;
	margin: 10px 0;
}

.detail text {
	line-height: 105rpx;
	font-size: 21rpx;
}

.btn-small {
	float: right;
	width: 140rpx;
	height: 50rpx !important;
	margin-right: 10px;
	font-size: 21rpx;
	color: #FFFFFF;
}

.detail-box {
	width: 100%;
	background: #fff;
	padding: 24rpx;
	box-sizing: border-box;
}
.detail-box text {
	line-height: 44rpx;
}

.title_big {
	color: #FABD50;
	font-size: 32rpx;
	font-weight: 600;
	display: inline-block;
	padding: 0 12rpx;
}

.close {
	width: 80rpx;
}

.my-btn {
	height: 94rpx;
	background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
	box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
	border-radius: 24px;
	font-family: PingFangSC-Medium;
	color: #FFFFFF;
	letter-spacing: 0;
	text-align: center;
}

.my-btn-grpup {
	height: 120rpx;
	line-height: 120rpx;
	vertical-align: middle;
	text-align: center;
}

.btns-group {
	width: 100%;
	position: sticky;
	top: 5px !important;
	bottom: 0 !important;
	text-align: center;
	display: flex;
	flex-direction: row;
	align-items: flex-end;
}

.btns-group button:first-child {
	background-color: #458DF5;
	color: #FFFFFF;
	flex: 1;
	font-size: 36rpx;
	outline: none;
	border: none;
	margin: 0;
	padding: 0;
	border: 1px solid transparent;
	border-radius: 0;
	border-top-left-radius: 6px;
}

.btns-group button:nth-child(2) {
	background-color: #54BE7A;
	color: #FFFFFF;
	flex: 1;
	font-size: 36rpx;
	outline: none;
	border: none;
	margin: 0;
	padding: 0;
	border: 1px solid transparent;
	border-radius: 0;
}

.btns-group button:last-child {
	background-color: #FABD50;
	flex: 1;
	color: #FFFFFF;
	font-size: 36rpx;
	outline: none;
	border: none;
	margin: 0;
	padding: 0;
	border: 1px solid transparent;
	border-radius: 0;
	border-top-right-radius: 6px;
}

.zj {
	display: flex;
	justify-content: space-between;
	background: #FFFFFF;
	height: 108rpx;
	line-height: 108rpx;
	font-size: 24rpx;
	color: #333333;
	border-bottom: 1px solid #CCCCCC;
	align-items: center;
}
.detail-title {
	font-size: 14px;
	font-weight: 400;
	text-align: left;
}
</style>
